<template>
  <div>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      append-to-body
      width="80%"
      @close="handleClose"
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
        @submit.native.prevent
      >
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="输入塘口名称"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['production:pond:add']"
            >新增塘口</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="tableList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="序号" type="index" align="center">
          <template slot-scope="scope">
            <span>{{
              (queryParams.pageNum - 1) * queryParams.pageSize +
              scope.$index +
              1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="塘口名称"
          align="center"
          key="name"
          prop="name"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <div class="text-detail" @click="handleToDetail(scope.row)">
              {{ scope.row.name || "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="面积" align="center" key="area" prop="area">
          <template slot-scope="scope">
            <div>{{ scope.row.area }}亩</div>
          </template>
        </el-table-column>
        <el-table-column label="类型" align="center" key="type" prop="type">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.biz_culture_pond_type"
              :value="scope.row.type"
            ></dict-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="负责人"
          align="center"
          key="director"
          prop="director"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.director || "-" }}</div>
          </template>
        </el-table-column>

        <el-table-column
          label="设备数量"
          align="center"
          key="deviceCnt"
          prop="deviceCnt"
        >
        </el-table-column>
        <el-table-column
          label="养殖品种"
          align="center"
          key="breedSpecies"
          prop="breedSpecies"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.breedSpecies || "-" }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="养殖天数"
          align="center"
          key="breedDays"
          prop="breedDays"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.breedDays || "-" }}天</div>
          </template>
        </el-table-column>
        <el-table-column
          label="消耗饲料"
          align="center"
          key="usedFeed"
          prop="usedFeed"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.usedFeed || "-" }}公斤</div>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
        <el-button @click="handleClose">关 闭</el-button>
      </div>
    </el-dialog>

    <Edit
      :visible.sync="editOpen"
      :params="editParams"
      @success="getList"
    ></Edit>
    <Detail :visible.sync="detailOpen" :params="detailParams"></Detail>
  </div>
</template>
  
  <script>
import { detail, list } from "@/api/production/pond";
import ImagePreview from "@/components/ImagePreview";
import Edit from "./edit.vue";
import Detail from "./detail.vue";
export default {
  name: "production-pond_select",
  components: { ImagePreview, Edit, Detail },
  dicts: ["biz_culture_pond_type"],
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    params: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      detailOpen: false,
      detailParams: {
        id: "",
      },
      // 编辑模态框参数
      editParams: {
        type: "add",
        title: "",
      },
      // 是否显示弹出层
      editOpen: false,
      selectionList: [], // 多选数据列表
      placeholderImg: require("@/assets/images/production.png"),
      baseUrl: process.env.VUE_APP_BASE_API,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      queryParams: { id: undefined },
      title: "塘口列表",
      // 遮罩层
      loading: false,
      tableList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        productionBaseId: undefined,
      },
    };
  },
  watch: {
    visible: {
      handler(val) {
        this.open = val;
        this.title = this.params.title;
        if (val) {
          this.queryParams.productionBaseId = this.params.baseId;
          this.getList();
        }
      },
    },
  },
  methods: {
    handleSubmit() {
      this.$emit("selection", this.selectionList);
    },
    /** 查看详情 */
    handleToDetail(row) {
      this.detailParams = { title: "塘口信息", id: row.id };
      this.detailOpen = true;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectionList = selection.map((item) => item.userId);
    },
    /** 数据列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.editParams = { title: "添加塘口", type: "add" };
      this.editOpen = true;
    },
    // 取消按钮
    handleClose() {
      this.$emit("update:visible", false);
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
  },
};
</script>
  
  <style scoped lang="scss">
.relevance-card {
  width: 100%;
  height: 100%;
  overflow: hidden;
  & > li {
    width: 24%;
    height: 120px;
    float: left;
    margin-right: calc(4% / 3);
    margin-bottom: calc(4% / 3);
    border-radius: 3px;
    background-color: #fff;
    padding: 10px;
    box-sizing: border-box;
    box-shadow: 0 0 3px 0 rgba($color: #000000, $alpha: 0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    &:nth-child(4n) {
      margin-right: 0;
    }
    &:nth-last-child(-n + 4) {
      margin-bottom: 0;
    }
    .relevance-card-content {
      width: 100%;
      display: flex;

      & > img {
        width: 70px;
        height: 70px;
        margin-right: 10px;
        flex-shrink: 0;
      }
    }
  }
}

::v-deep .el-descriptions__body {
  background-color: transparent !important;
}
</style>